<form id="auto-data-form" action="resource/saveOrUpdate" class="form-horizontal bv-form" method="post" role="form">
<div class="col-sm-7">
	<div style="display: none;">
		<input id="model.id" name="model.id" value="#(model.id)" placeholder="资源主键" type="hidden" />
		<input id="model.parentId" name="model.parentId" value="#(model.parentId)" placeholder="上级节点" type="hidden" />
		<input id="model.sort" name="model.sort" value="#(model.sort)" placeholder="排序" type="hidden" />
		<input id="model.auth" name="model.auth" value='#(model.auth)' placeholder="资源权限明细JSON" type="hidden" />
	</div>
	<div class="form-group">
		<label for="mode.val" class="col-sm-2 control-label">上级资源</label>
		<div class="col-sm-10">
			<input value="#(parent.name??)" class="form-control input-md" readonly="readonly"/>
		</div>
	</div>
	<div class="form-group">
		<label for="mode.name" class="col-sm-2 control-label">资源名称</label>
		<div class="col-sm-10">
			<input id="model.name" name="model.name" value="#(model.name)" placeholder="名称" class="form-control input-md" required maxlength="64"/>
		</div>
	</div>
	
	<div class="form-group">
		<label for="mode.uri" class="col-sm-2 control-label">功能URI</label>
		<div class="col-sm-10">
			<input id="model.uri" name="model.uri" value="#(model.uri)" placeholder="功能URL" class="form-control input-md" maxlength="128"/>
		</div>
	</div>
	
	<div class="form-group">
		<label for="mode.img" class="col-sm-2 control-label">资源图标</label>
		<div class="col-sm-10">
			<div class="input-group">
			<input id="model.icon" name="model.icon" value="#(model.icon)" placeholder="菜单图片" class="form-control input-md" maxlength="256" 
			onblur="javascript:$(this).parent().find('i').attr('class','').addClass('fa ' + this.value);"/>
			<span class="input-group-addon"><i class="fa #(model.icon)"></i></span>
			</div>
		</div>
	</div>

	<div class="form-group">
		<label for="model.target" class="col-sm-2 control-label">加载容器</label>
		<div class="col-sm-10">
			<input id="model.target" name="model.target" value="#(model.target)" placeholder="加载容器" class="form-control input-md" maxlength="32"/>
		</div>
	</div>
	
	<div class="form-group">
		<label for="mode.state" class="col-sm-2 control-label">资源状态</label>
		<div class="col-sm-10">
			#@dict_select("model.state",model.state,"DATA_STATE",false,"资源状态","required")
		</div>
	</div>
	
	<div class="form-group">
		<label for="mode.remark" class="col-sm-2 control-label">资源描述</label>
		<div class="col-sm-10">
			<textarea id="model.remark" name="model.remark" placeholder="描述" class="form-control input-md" maxlength="1024">#(model.remark)</textarea>
		</div>
	</div>
	#set(mgrPv=com.yj.auto.helper.AuthHelper::auth("resource/index", "all", session.SESSION_USER))
	#if(mgrPv)
	<div class="form-group text-center">
		<button type="button" class="btn btn-success auto-btn auto-submit-ajax" data-callback="_callback"><i class="fa fa-check-square"></i>&nbsp;&nbsp;保存</a></button>
	</div>	
	#end
</div>
<div id="resource_items" class="col-sm-5">
	<div class="form-group text-center">
		<label class="col-sm-11"><h4>资源权限</h4></label>
		#if(mgrPv)
		<button type="button" class="col-sm-1 btn btn-info btn-circle res_add" onclick="_add_item({});" style="float: right;"><i class="fa fa-plus"></i></button>
		#end
	</div>	
	<div class="form-group">
		<label class="col-sm-5">资源编号</label>
		<label class="col-sm-6">资源编号</label>
		#if(mgrPv)
		<label class="col-sm-1"删除</label>
		#end
	</div>
</div>

</form>
<script type="text/javascript">
	var res_item_idx=0;
	function _add_item(item){
		var key="items["+(res_item_idx++)+"]";
		var tr="<div class='form-group'>";
		tr+="<div class='col-sm-5'><input id='"+key+".code' name='"+key+".code' value='"+trim(item.code)+"' placeholder='编号' class='form-control input-sm' required></div>";
		tr+="<div class='col-sm-6'><input id='"+key+".name' name='"+key+".name' value='"+trim(item.name)+"' placeholder='名称' class='form-control input-sm' required></div>";
		#if(mgrPv)
		tr+="<div class='col-sm-1'><button type='button' class='btn btn-info btn-circle res_del' onclick='_del_item(this);'><i class='fa fa-minus'></i></button></div>";
		#end
		tr+="</div>";
		tr=$(tr);
		$("#resource_items").append(tr);
		$("form.bv-form").bootstrapValidator("addField",tr.find("input"));  
	}
	function _del_item(obj){
		var tr=$(obj).parents("div.form-group:first");
		//$("form.bv-form").bootstrapValidator("removeField",tr.find("input"));  
		tr.remove();
	}
	function _callback(data){
		if(data.success) {
			jid("model.id").val(data.data);
			_updateZtreeNode(data.data,jid("model.name").val());
		}
	}	
	$(document).ready(function() {
		var items=null;
		if(jid("model.id").val()==""){//默认
			items=[{code:'all',name:'所有权限'},{code:'add',name:'新增'},{code:'edit',name:'修改'},{code:'del',name:'删除'}];
		}else{
			if(jid("model.auth").val()!="")
			items=JSON.parse(jid("model.auth").val());
		}
		for(var i=0;null!=items&&i<items.length;i++){
			_add_item(items[i]);
		}
	});
</script>